;***********************************
; GTD functions (gdt.inc)
; Reindeer OS / Stage 2 Bootloader
; **********************************

bits 16

;***********************************
; InstallGDT()
;	- install GDT table to memory
;***********************************

InstallGDT:
	cli						; dont serve interrupts
	pusha					; save all registers
	lgdt	[toc]			; load GDT to special register GDTR
	sti						; enable servering interrups
	popa					; restore all registers
	ret						; go back to main program sequence

;**********************************
; Global Descriptor Table (GDT)
;**********************************

gdt_def:
; null descriptor (first 64 bites)
	dd 0
	dd 0
; code section
	dw 0FFFFh				; low limit
	dw 0					; low base
	db 0					; base middle
	db 10011010b			; access rights
	db 11001111b			; granuality
	db 0					; base high
; data section
	dw 0FFFFh				; low limit (same as code)
	dw 0					; low base 
	db 0					; base middle
	db 10010010b			; access
	db 11001111b			; granuality
	db 0					; base high

end_gdt:
toc:
	dw end_gdt - gdt_def - 1			; size of GDT
	dd gdt_def							; base of GDT

%define NULL_DESC 0
%define CODE_DESC 0x8
%define DATA_DESC 0x10

		
